package com.frx.leetcode.packageone;

/**
 * Created by xurenfeng on 2019/2/13.
 * Input:5
 * Output:True
 * Explanation: 1*1+2*2 = 5
 * 描述：判断一个数是否为两数平方之和
 */
public class SquareSum {
    public static void main(String [] args){
        System.out.println(judgeSquareSum(8));
    }

    public static boolean judgeSquareSum(int a){
        int i = 0,j = (int) Math.sqrt(a);
        while (i<=j){
            int sum = i*i + j*j;
            if(sum == a){
                return true;
            }else if (sum<a){
                i++;
            }else {
                j--;
            }
        }
        return false;
    }
}
